<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>内容管理</title>
<link href="/res/back/css/base.css" rel="stylesheet" type="text/css" />
<link href="/res/third/bootstrap3/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="/res/common/js/jquery.1.9.1.min.js" type="text/javascript"></script>
<script src="/res/third/artDialog/jquery.artDialog.js" type="text/javascript"></script>
<script src="/res/third/validate/jquery.validate.js" type="text/javascript"></script>
<script src="/res/third/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/res/third/easyUI/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
<link href="/res/third/powerFloat/css/powerFloat.css" rel="stylesheet" type="text/css" />
<script src="/res/third/powerFloat/js/mini/jquery-powerFloat-min.js" type="text/javascript"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/res/third/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/res/third/ueditor/lang/zh-cn/zh-cn.js"></script>
<style type="text/css">
		.lpdiv{display: inline-block;float: left;margin-left: 220px;margin-top: 15px;width: 100%;}
		.showimgs{display:inline-block;}
		.delimgas{display:inline-block;margin-left:50px;cursor:pointer;}
	#proTable td {
		padding: 0 5px;
	}
</style>

</head>
<body>
    <div class="panel panel-info" style="height: 100%;overflow-y:scroll;">
	       <div class="panel-heading">
	          <h3 class="panel-title">首页爆品推荐</h3>
	        </div>
        <div class="panel-body" style="overflow: hidden;border-bottom: none;">
			<form class="form-horizontal" role="form"   id="mainForm">
			  <input type="hidden" name="id" >
			  <div class="form-group">
			    <label for="title" class="col-sm-2 control-label" >选择商品:</label>
			    <input type="hidden" name="productId" id="productId">
			    <div class="col-sm-10">
					<table id="proTable" >
						<tr>
						  <td>
							  <input type="text" placeholder="选择商品" onclick="chooseProduct()"  id="name" name="name" style="cursor: pointer;" readonly>
						  </td>
						  <td>
							  <span style="font-size:30px;cursor:pointer" onclick="addProduct()">+</span>
						  </td>
						</tr>
					</table>
			    </div>
             </div>
			 
			 <div class="form-group" style="margin-top: 10px;">
					<div style="margin-left:300px;">
						<button onclick="insert();" type="button" class="btn btn-info">立即提交</button>
					</div>
			</div>
			</form>
        </div>
        
      </div>
      
     
     
     <div style="display: none;width: 600px;" id="providerDiv">
      		<div style="border: 1px solid #ddd;padding-bottom: 8px;">
      			<div>
      				<input style="display: inline-block;width: 160px;height: 30px;margin: 8px;" type="text" class="form-control" id="so_companyname" placeholder="请输入公司名字" name="so_companyname">
      				<button type="button" class="btn btn-info btn-xs delbtn" onclick="searchProvider()">查询</button>
      			</div>
      			<table class="table table-hover table-bordered table-striped table-condensed" id="companyTab" style="margin-bottom: 8px;">
					<tr id="ftr">
						<th width="50%">商品名称</th>
						<th width="50%">来源公司</th>
					</tr>
				</table>
				<div style="text-align: right;padding-right: 8px;">
					<button type="button" class="btn btn-primary btn-xs delbtn" onclick="pageUp()">上一页</button>
					<button type="button" class="btn btn-primary btn-xs delbtn" onclick="pageNext()">下一页</button>
				</div>
      		</div>
      		<input id="pageNo" type="hidden" value="1">
      		<input id="pageTotal" type="hidden">
      		<input id="so_companyname_back" type="hidden">
      </div>
     
      
<script type="text/html" id="productTemplate">
    <tr>
           <input type="hidden" name="productId" id="productId">
        <td>
            <input type="text" placeholder="选择商品" onclick="chooseProduct(this)" name="name" id="name" style="cursor: pointer;" readonly>
        </td>
        
        <td>
            <span style="font-size:30px;cursor:pointer" onclick="addProduct()">+</span>
        </td>
    </tr>
</script>


<script>
    
      function addProduct(){
          $('#proTable').append($('#productTemplate').html());
      }
      
      function removeProduct(obj){
    	  $(obj).parents("tr").remove();
      }
     
    
        //立即提交按钮
     		$.each($('#proTable tr'), function(i, v) {
     			var $seqInput = $(v).find('input[name$=seq]');
     			var $productId = $(v).find('input[name$=productId]');
     			$seqInput.prop('name', 'productList[' + i + '].seq');
     			$productId.prop('name', 'productList[' + i + '].productId');
     		});
     		
     	function insert(){
     		$.ajax({
     			type:"post",
     			dataType:"json",
     			url:"/shop/insert.do",
     			data:$("form").serialize(),
     			success:function(aj){
     				if(aj.success){
     					location.reload();
     					alert(aj.msg);
     				}
     			}
     		});
     	}

      	var index;
     	var dialogAddCom;
			index = $(obj).parents('tr').index();
     		dialogAddCom = art.dialog({
     		        title: "选择商品",
     		        lock:true,
     		        content: document.getElementById('providerDiv')
     		    });
     		initProvider(1);
     	}

     	function initProvider(pageNo,so_companyname){
     		 art.dialog.post({
     				url : '/hotfloor/chooseproduct.do',
     				data : {
     					pageNo : pageNo,so_companyname:so_companyname, so_categoryTId : $('#categoryId').val()
     				},
     				success : function(data){
     					if(data.success){
     						$("#ftr").nextAll().remove();
     						var productList=data.attributes.productList;
     						for (var i = 0; i < productList.length; i++) {
     							$("#companyTab").append("<tr>"
     												        +"<td  style='cursor: pointer;' onclick='sendBackCName("+productList[i].id+",\""+productList[i].name+"\" )' >"+productList[i].name+"</td>"
     												        
     												        +"<td>"+productList[i].companyName+"</td>"
     												   +"</tr>");	
     						}
     						
     						$("#pageTotal").val(data.attributes.totalPage);
     						$("#pageNo").val(data.attributes.pageNo);
     						$("#so_companyname_back").val(data.attributes.so_companyname)
     					}else{
     						error_msg(data.msg , function(){location.reload();});
     					}
     				}
     		 
     		},"数据初始化中.... ");
     		 
     	}

     	function sendBackCName(cid,cname){
			$("#protable tr:eq(" + index + ")").find('input[name=name]').val(cname);
     		 $("#name").val(cname);
     		 $("#productId").val(cid);
     		 dialogAddCom.close();
     	}

     	function searchProvider(){
     		var so_companyname=$("#so_companyname").val();
     		initProvider(1,so_companyname);
     	}

     	function pageUp(){
     		var pageNo=$("#pageNo").val();
     		pageNo=parseInt(pageNo);
     		if(pageNo!=1){
     			 pageNo=pageNo-1;
     		}
     		var so_companyname=$("#so_companyname_back").val();
     		initProvider(pageNo,so_companyname);
     	}
     	function pageNext(){
     		var pageNo=$("#pageNo").val();
     		var pageTotal=$("#pageTotal").val();
     		pageNo=parseInt(pageNo);
     		if(pageNo!=pageTotal){
     			 pageNo=pageNo+1;
     		}
     		var so_companyname=$("#so_companyname_back").val();
     		initProvider(pageNo,so_companyname);
     	}
     	    	
</script>
</body>
</html>